package com.wss.module.wan.ui.project.adapter;

import com.orhanobut.logger.Logger;
import com.wss.common.base.adapter.BaseListAdapter;
import com.wss.common.base.adapter.listener.OnListItemClickListener;
import com.wss.common.base.adapter.superadapter.SuperViewHolder;
import com.wss.common.utils.ImageUtils;
import com.wss.common.utils.PxUtils;
import com.wss.common.utils.TextUtils;
import com.wss.module.wan.ResourceTable;
import com.wss.module.wan.bean.Article;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.app.Context;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class ProjectListAdapter extends BaseListAdapter<Article> {

    /**
     * 常规列表重写该方法
     *
     * @param context     context
     * @param list        数据源
     * @param listener    Item点击回调
     */
    public ProjectListAdapter(Context context, List<Article> list, OnListItemClickListener<Article> listener) {
        super(context, list, ResourceTable.Layout_wan_item_of_project_list, listener);
    }

    @Override
    public void onBindData(@NotNull SuperViewHolder holder, int layoutPosition, @NotNull Article data) {
        Image imageView = holder.findViewById(ResourceTable.Id_iv_img);
        Text tvDes = holder.findViewById(ResourceTable.Id_tv_des);
        if (!TextUtils.isEmpty(data.getEnvelopePic())) {
            ImageUtils.loadImage(imageView, data.getEnvelopePic());
            imageView.setVisibility(Component.VISIBLE);
        } else {
            imageView.setVisibility(Component.HIDE);
            tvDes.setMinHeight(PxUtils.vp2px( 25));
        }
        Logger.e("getMinHeight:" + tvDes.getMinHeight());
        holder.setText(ResourceTable.Id_tv_des, data.getDesc());
        holder.setText(ResourceTable.Id_tv_author, String.format("作者：%s", data.getAuthor()));
        holder.setText(ResourceTable.Id_tv_date, data.getNiceDate());
    }
}
